package edu.vital.energy.longevity.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@Service
public class MenuService {
    
    private final ObjectMapper objectMapper;
    
    public MenuService(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }
    
    @SuppressWarnings("unchecked")
    public Map<String, Object> getMenuList() {
        try {
            // 从classpath加载JSON文件
            InputStream inputStream = getClass().getResourceAsStream("/menu/menu-list.json");
            Map<String, Object> menuData = objectMapper.readValue(inputStream, Map.class);
            
            // 构造返回格式
            Map<String, Object> result = new HashMap<>();
            result.put("code", 0);
            result.put("list", menuData.get("data"));
            
            return result;
        } catch (Exception e) {
            throw new RuntimeException("Failed to load menu data", e);
        }
    }
} 